//index.js
//获取应用实例
var app = getApp();
var openId;
var userId;
Page({
    data: {
        haveCinema: false,
        winHeight: "",//窗口高度
        currentTab: 0, //预设当前项的值
        scrollLeft: 0, //tab标题的滚动条位置
        courseList: []
    },
    onLoad: function (option) {
        let that = this;
        // wx.showNavigationBarLoading()
        wx.showLoading({
            title: '加载中',
            mask: true
        });
        that.getOrderListAppLet();
    },
    // 课程详情
    goPage: function (e) {
        console.log(e)
        let productid = e.currentTarget.dataset.productid;
        let url = e.currentTarget.dataset.url;
        let userid = e.currentTarget.dataset.userid;
        wx.navigateTo({
            url: url + '?productId=' + productid + '&userId=' + userid
        });
    },
    // 我要购买
    goBuy: function (e) {
      console.log(e)
        let url = e.currentTarget.dataset.url;

        wx.switchTab({
            url: url
        });
    },
    // 我的课程列表
    getOrderListAppLet:function(){
        let that=this;
        openId = wx.getStorageSync('openId');
        userId = wx.getStorageSync('userId');
        wx.request({
            url: app.globalData.url + "/getOrderListAppLet",
            data: {
                openId: openId,
                userId: userId
            },
            success: function (res) {
                console.log(res.data.result);
                // wx.hideNavigationBarLoading();
                wx.hideLoading();
                if (res.data.result){
                    var cl = res.data.result;
                    for (var i = 0, count = cl.length; i < count; i++) {
                        if (cl[i].course.subject === 1) {
                            cl[i].course.subject = '../img/111.png';//微课
                        } else if ((cl[i].subject === 2)) {
                            cl[i].course.subject = '../img/222.png';//精品课
                        } else {
                            cl[i].course.subject = '../img/333.png';//系统课
                        }
                    }
                    that.setData({
                        courseList: cl,
                        courseHas: true,
                        courseNot: false,
                    })
                }else{
                    that.setData({
                        courseHas: false,
                        courseNot: true,
                    })
                }
                
            }
        })
    }
})
